<template>
  <div class="popupMask">
    <div class="popupPenal" style="min-width: 70%;min-height: 70%;">
      <div class="popPenalTitle">
        <div class="popPenalTitleName">
          选择物资
        </div>
        <div class="popupClose" v-on:click="close">
          <el-button size="mini">关闭</el-button>
        </div>
      </div>
      <div class="penalContent">
        <div>
          <div class="penalrow selectw100">
            <div class=" width100 ">
              <div class="inlineblock verticalmiddle">
                物资类型
              </div>
              <div class="inlineblock verticalmiddle informationItem">
                <el-cascader clearable @change="cascaderChange" expand-trigger="hover" :options="enableMaterTypeList" v-model="selectedOptions2"
                  size="mini" style="width:100%;">
                </el-cascader>
              </div>
            </div>
          </div>
          <div class="penalrow selectw100">
            <div class=" width100 ">
              <div class="inlineblock verticalmiddle">
                物资名称
              </div>
              <div class="inlineblock verticalmiddle informationItem">
                <el-input size="mini" placeholder="物资名称" v-model="enMaterialParams.materialName" @change="readStockByMatarialCode" clearable></el-input>
              </div>
            </div>
          </div>
          <div class="penalrow selectw100">
            <div class=" width100 ">
              <div class="inlineblock verticalmiddle">
                物资批号
              </div>
              <div class="inlineblock verticalmiddle informationItem">
                <el-input size="mini" placeholder="物资名称" v-model="enMaterialParams.batch" clearable @change="batchChange"></el-input>
              </div>
            </div>
          </div>
          <div class="penalrow selectw100">
            <el-table :default-sort="{prop: 'validitydate', order: 'descending'}" :data="wuzi" size='mini' :height='biaoyangTableHeight'
              @row-dblclick="dblclick" :row-class-name="tableRowClassName" @selection-change="handleSelectionChange" style="width: 100%; margin-top: 20px;">
              <el-table-column type="selection" width="55">
              </el-table-column>
              <el-table-column prop="number" min-width="100" show-overflow-tooltip label="物资编号">

              </el-table-column>
              <el-table-column prop="materialTypeName" show-overflow-tooltip label="物资类型" min-width="100">
              </el-table-column>
              <el-table-column prop="materialName" show-overflow-tooltip label="物资名称" min-width="100">
              </el-table-column>
              <el-table-column prop="batch" min-width="100" show-overflow-tooltip label="物资批号">
              </el-table-column>
              <el-table-column prop="qty" label="库存余量">
              </el-table-column>

              <el-table-column prop="purity" label="纯度" width="90">
              </el-table-column>
              <el-table-column prop="concentration" label="浓度" width="90">
              </el-table-column>
              <el-table-column prop="medium" label="介质" min-width="90" show-overflow-tooltip>
              </el-table-column>
              <el-table-column prop="spce" label="包装规格">
              </el-table-column>
              <el-table-column prop="validitydate" label="有效期" min-width="110">
            </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div class=" penalFooter" style="text-align: right;">
        <!-- <el-button v-if="newOrEdit=='new'" class="penalButton" type="primary" size="mini" v-on:click="close">新增</el-button>
              <el-button v-if="newOrEdit=='edit'" class="penalButton" type="primary" size="mini" v-on:click="close">确定</el-button> -->
        <el-button class="penalButton" type="primary" size="mini" v-on:click="queding">添加</el-button>
        <el-button class="penalButton" size="mini" v-on:click="close">取消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  import { mapState } from 'vuex'

  export default {
    props: [],
    data() {
      return {
        yesornoValue: '1',
        enableStatusValue: '1',
        options: [],
        selectedOptions2: [],
        tableData6: [],
        multipleSelection: [],

        wuzi: [],
        enMaterialParams: { "materialName": "", "materialType": "", "batch": "" }
      }
    },
    computed: {
      ...mapState(['enableMaterTypeList']),
      biaoyangTableHeight() {
        return ((window.innerHeight - 90) * 0.7 - 250)
      }
    },
    mounted() {

      this.readStockByMatarialCode()
      console.log(this.$parent.outstockParams.outstockdetBeanList)
      //			this.readEnableMaterTypeList()

    },
    methods: {
      tableRowClassName({ row, rowIndex }) {

        if (row.validitydate < this.util.date()) {
          return "useless-row"
        }

        return '';
      },
      cascaderChange() {
        console.log(this.selectedOptions2)
        this.enMaterialParams.materialType = this.selectedOptions2[this.selectedOptions2.length - 1]
        this.readStockByMatarialCode()
      },
      batchChange() {
        this.readStockByMatarialCode()
      },

      //	16、(1)交互名称：根据materialCode获取相同物资、不同hashcode的库存余量
      // (2)url:readStockByMatarialCode.htm
      // (3)参数：materialCode
      readStockByMatarialCode() {
        this.$http({
          apiUrl: 'resource/readStockByMatarialCode.htm',
          method: 'post',
          params: this.enMaterialParams,
          isJson: true
        }).then(res => {
          if (res.code === 0) {
            console.log(res)
            this.wuzi = res.data
          }
        })
      },
      close() {
        this.$parent.xuanzewuziShow = false;
      },
      queding() {
        this.multipleSelection.forEach(item => {
          item.stockQty = item.qty
          item.total = item.qty
          item.qty = ''
        })
        // materialCode 以前unique是materialCode
        let addArr = this.util.repeatData({ old: this.$parent.outstockParams.outstockdetBeanList, new: this.multipleSelection, unique:'hashcode' })

        this.$parent.outstockParams.outstockdetBeanList = addArr;
        this.close();
        // 	alert(111)
      },
      dblclick(row, column, event) {
        //  	console.log(row,column,event)
        //		row.qty = '';
        this.multipleSelection = [row];
        this.queding()
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;

      },

    }
  }

</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
  .el-table .useless-row {
    background: #ccc;
  }
</style>
<style scoped>
  .tabName {
    display: inline-block;
    cursor: pointer;
    padding: 0px 15px;
    border: 1px solid #b7b7b7;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    color: #a9a9a9;
  }

  .activeTab {
    color: #409eff;
  }

  .tabPageContent {}
</style>
